package com.thoughtworks.impersonator.http.record;

import static com.thoughtworks.impersonator.http.IntegrationTestUtils.buildContent;
import static com.thoughtworks.impersonator.http.IntegrationTestUtils.post;
import static com.thoughtworks.impersonator.http.IntegrationTestUtils.startServer;
import static org.junit.Assert.assertEquals;

import java.io.File;

import org.eclipse.jetty.server.Server;
import org.junit.Test;

import com.thoughtworks.impersonator.http.message.RequestIdentifier;
import com.thoughtworks.impersonator.http.test.FixedUidRequestIdentifier;

public class RecorderTest {

    private static final int SERVER_PORT = 9920;
    private static final int RECORDER_PORT = SERVER_PORT + 1;

    @Test
    public void shouldRecord() throws Exception {
        RequestIdentifier requestIdentifier = new FixedUidRequestIdentifier("w00t");

        Server server = startServer(SERVER_PORT, "w00t", buildContent(65535) + "\r\n");
        Recorder recorder = new Recorder(RECORDER_PORT, "127.0.0.1", SERVER_PORT, new File("target/tmp"), requestIdentifier);
        String returned = post("http://127.0.0.1:" + RECORDER_PORT, buildContent(65535));
        recorder.stop();
        server.stop();

        assertEquals("w00t", returned);
    }

}
